
	/**
	*封装上传方法
	*参数:upDom：上传图片按钮的id  string
	* imgDom:图片回显的ID string
	* url:请求的路径
	* field:文件域的名字
	* hideId:隐藏域id
	* data:额外的参数
	* posterWidth: 指定宽度
	* posterHeight：指定高度
	* size: 指定大小
	*/
	function w_uplode(upDom,imgDom,url,field,hideId,data,successBack,errorBack,posterWidth = 0,posterHeight = 0,size = 2048) {
		if(successBack == undefined){
			successBack = function (res){
				layer.closeAll('loading');
				if (res.code > 0) {
				  return layer.msg(res.msg);
				}
                layer.msg('上传成功');
				$(hideId).val(res.data.src)
			}
		}
		
		if(errorBack == undefined){
			errorBack = function (){
				layer.closeAll('loading');
				layer.alert('上传失败，请重试！');
			}
		}
		layui.use('upload', function(){
		  var $ = layui.jquery
		  ,upload = layui.upload;
		var uploadInst = upload.render({
		  elem: upDom
		  , url: url
		  , data: data
		  , exts: 'jpg|png|jpeg'
		  , size: 1024 * 2
		  , drag: true
		  , auto: false
		  ,field: field
		  , choose: function(obj) {
			obj.preview(function(index, file, result) {
			  var img = new Image();
			  img.onload = function() {
				if(posterWidth !== 0 && posterHeight !== 0){
					if (posterWidth == img.width && posterHeight == img.height) {
					  $(imgDom).attr('src', result); //图片链接（base64）不支持ie8
					  obj.upload(index, file);
					} else {
					  layer.alert('图片尺寸必须为：' + posterWidth + 'x' + posterHeight + '(px)');
					}
				} else {
					$(imgDom).attr('src', result); //图片链接（base64）不支持ie8
					obj.upload(index, file);
				}
			  };
			  img.src = result;
			});
		  }
		  , before: function(obj) {
			layer.load();
		  }
		  , done: successBack
		  , error: errorBack
		})
		})
	}
	
	/**
	*
	* table 方法封装，国际化
	*/
	function w_table(tablDom){
		tablDom.DataTable({
          'paging'      : true,
          'lengthChange': false,
          'searching'   : true,
          'ordering'    : false,
          'info'        : true,
          'autoWidth'   : true,
          'zeroRecords': "没有内容",
          'search': '<span class="label label-success">搜索：</span>',
		   'language': {
			"sProcessing": "处理中...",
			"sLengthMenu": "显示 _MENU_ 项结果",
			"sZeroRecords": "没有匹配结果",
			"sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
			"sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
			"sInfoFiltered": "(由 _MAX_ 项结果过滤)",
			"sInfoPostFix": "",
			"sSearch": "搜索:",
			"sUrl": "",
			"sEmptyTable": "表中数据为空",
			"sLoadingRecords": "载入中...",
			"sInfoThousands": ",",
			"oPaginate": {
				"sFirst": "首页",
				"sPrevious": "上页",
				"sNext": "下页",
				"sLast": "末页"
			}
			},
			"aoColumnDefs": [
            {　　//为每一行数据添加一个checkbox，
                'targets': 0,
                'searchable':false,
                'orderable':false,
                'className': 'dt-body-center',
                'render': function (data, type, row){
                    return '<input class="checkbox_select" onclick="w_checkSon(this)" type="checkbox" name="id[]" value="' + $('.checkSon').val() + '">';
                }
            },
			{
                "aTargets": [0], //title
                "mRender": function (title, type, row) {
                    return '<a href="loan/request/' + row.id + '" target="_blank">' + title + '</a>';
                }
            }
			]
        });
	}

    /**
	 *封装layui自带table方法
	 * elem: 表格ID
	 * url: 方法名，自动回找当前控制器下的方法
	 * cols: 值为数值，定义列头
	 * toolbarDemo: 操作栏，待确定是否需要
	 * title: 表格标题w_batchHandler
     */
     function w_layuiTable(elem,url,cols=[],toolbarDemo = '',title = ''){
            var table = layui.table;

            //渲染表格
            table.render({
                elem: elem
				, id: 'test'
                , url: url
				, toolbar: toolbarDemo //操作头
				, title: title //标题
                , page: true
                , cols: [cols]
            });
	}



	
	/*
	*  封装ajax提交方法
	*  1，form dom
	*  2，成功回调
	*  3，错误回调
	*/
	function w_ajaxSubmit(formDom,successBack,errorBack){
		if(successBack == undefined){
			successBack = function (data){
				if(data.code==0){
				  layer.msg(data.msg);
				}else{
				  layer.msg(data.msg,{icon:1,time:500},function(){
					$("#reset").click();
					lotus_close();
					parent.location.reload();
				  });
				}
			}
		}
		if(errorBack == undefined){
			errorBack = function(XmlHttpRequest,textStatus,errorThrown){
				layer.msg('操作失败:服务器处理失败');
			}
		}
		var options = {
              type:'post',           //post提交
              //url:'http://ask.tongzhuo100.com/server/****.php?='+Math.random(),   //url
              dataType:"json",        //json格式
              data:{},    //如果需要提交附加参数，视情况添加
              clearForm: false,        //成功提交后，清除所有表单元素的值
              resetForm: false,        //成功提交后，重置所有表单元素的值
              cache:false,
              async:false,          //同步返回
              success:successBack,
			  error:errorBack
            };
          layui.use('form', function(){
            var form = layui.form;
            formDom.ajaxForm(options).submit(function(data){});
		});
	}
	
	
	function w_tableDel(id,url,delConfirm){
		if(delConfirm == undefined){
			delConfirm = '确认删除这行数据吗？'
		}
		layer.confirm(delConfirm, function(index){
            $.ajax({
              url: url,
              type: 'get',
              dataType: 'json',
              data: {id:id},
          })
          .done(function(data){
              //回调提示
              if(data.code==0){
                      layer.msg(data.msg,{icon:2,time:1000});
                  }else{
                      layer.msg(data.msg,{icon:1,time:1500},function(){
                          parent.location.reload();
                      });
              }
          })


       })
	}
	
	window.w_checkAll = function(selfcheck,checkSon = undefined) {
	    checkAll = checkSon === undefined ? $('.checkbox_select') : $('.' + checkSon)
		if(selfcheck.checked == true){
			checkAll.each(function(k,v){
				v.checked = true
			})
		}else{
			checkAll.each(function(k,v){
				v.checked = false
			})
		}
	}

	window.w_checkSon = function(selfcheck){
		if(selfcheck.checked === false){
			$('input[name=select_all]').each(function(k,v){v.checked = false})
		}else{
			f = true
			$('.checkbox_select').each(function(k,v){
				if(v.checked === false){
					f = false
				}
			})
			if(f === true){
				$('input[name=select_all]').each(function(k,v){v.checked = true})
			}
		}
	}

	

